using System.Drawing;
using GTA;
using GTA.UI;
using NativeUI;

namespace CustomPeds.Menus;

public class OnFootSexMenu : Script
{
    public static UIMenu menu = new UIMenu("", TextSetting.ofs_Menu, new Point(0, -107));
    private static bool inited;

    public OnFootSexMenu()
    {
        if (!inited)
        {
            Main.pool.Add(menu);
            Build();
            inited = true;
        }
    }

    public static void Open()
    {
        if (!inited) return;
        Build();
        menu.Visible = true;
        menu.RefreshIndex();
    }

    private static void Build()
    {
        menu.Clear();
        menu.SetBannerType(new UIResRectangle());

        void add(string text, OnFootSexScript.SexType type)
        {
            var it = new UIMenuItem(text);
            it.Activated += (m, i) => { StartOnFootSex(type); };
            menu.AddItem(it);
        }

        add(TextSetting.ofs_MenuItem_OralStand, OnFootSexScript.SexType.SexOralStand);
        add(TextSetting.ofs_MenuItem_SexStand, OnFootSexScript.SexType.SexStand);
        add(TextSetting.ofs_MenuItem_Sex2Stand, OnFootSexScript.SexType.Sex2Stand);
        add(TextSetting.ofs_MenuItem_OralSit, OnFootSexScript.SexType.SexOralSit);
        add(TextSetting.ofs_MenuItem_Oral2Sit, OnFootSexScript.SexType.SexOral2Sit);
        add(TextSetting.ofs_MenuItem_SexSit, OnFootSexScript.SexType.SexSit);
        add(TextSetting.ofs_MenuItem_SexLie, OnFootSexScript.SexType.SexLie);
        add(TextSetting.ofs_MenuItem_PoleDance, OnFootSexScript.SexType.PoleDance);
        add(TextSetting.ofs_MenuItem_RewardDance, OnFootSexScript.SexType.RewardDance);
        add(TextSetting.ofs_MenuItem_ExclusiveSingle, OnFootSexScript.SexType.ExclusiveDanceSingle);
        add(TextSetting.ofs_MenuItem_ExclusiveDouble, OnFootSexScript.SexType.ExclusiveDanceDouble);

        menu.RefreshIndex();
    }

    private static void StartOnFootSex(OnFootSexScript.SexType type)
    {
        try
        {
            if (Main.P1.Character == null || !Main.P1.Character.IsAlive)
            {
                Notification.PostTicker("玩家不可用，无法开始互动", true, false);
                return;
            }
            if (Main.P2.Character == null || !Main.P2.Character.IsAlive)
            {
                Notification.PostTicker("女友不可用，无法开始互动", true, false);
                return;
            }
            if (Game.Player.Character.IsInVehicle())
            {
                Notification.PostTicker("请先下车再进行互动", true, false);
                return;
            }
            Main.m_Status = Main.MaleStatus.OnFoot;
            OnFootSexScript.InitSexPlay(type);
            Main.OnMainMenuHidden();
            menu.Visible = false;
        }
        catch (System.Exception ex)
        {
            LogHelper.WriteException(ex, "StartOnFootSex - 进入步行特殊菜单");
            Notification.PostTicker($"进入互动失败: {ex.Message}", true, false);
        }
    }
}


